<!-- 中转页面 -->
<template>
  <div>

  </div>
</template>

<script>
import {setToken} from "../utils/auth";
import {getWebMenu} from "../api/permission";
import {setTree} from "../utils/menuAuth";
import {getUserInfo} from "../api/user";
import {setFirst, setSecond} from "../utils/menuIndex";
import {setHorizontalMenu} from "../utils/menuAuth";

export default {
  data(){
    return{

    }
  },
  mounted() {
    if (this.$route.query.t&&this.$route.query.c){
      setToken(this.$route.query.t);
      this.getUserInfo();
      this.getMenuList();
    }
  },

  methods:{
    getMenuList(){
      // type:-1横向菜单
      getWebMenu({type: -1,platformCode:parseFloat(this.$route.query.c)}).then((res) => {
        if (res.data) {
          setHorizontalMenu(JSON.stringify(res.data));
        }
      })
      // type:1竖向菜单
      getWebMenu({type: 1,platformCode:parseFloat(this.$route.query.c)}).then((menu) => {
        let data = menu.data;
        setTree(JSON.stringify(data));
        if (this.$route.query.url){
          data.forEach((item,i)=>{
            if (item.childPermissions){
              item.childPermissions.forEach((child,j)=>{
                if (this.$route.query.url.indexOf(child.url)!==-1){
                  setFirst(i);
                  setSecond(j);
                  location.replace(this.$route.query.url);
                }
              })
            }
          })
        }else{
          setFirst(0);
          setSecond(0);
          if (data[0].url) {
            this.$router.replace(data[0].url+'?key='+data[0].id);
          } else {
            if (data[0].childPermissions && data[0].childPermissions[0].url) {
              this.$router.replace(data[0].childPermissions[0].url+'?key='+data[0].childPermissions[0].id);
            }
          }
        }
      })
    },

    getUserInfo(){
      getUserInfo().then((res)=>{
        localStorage.setItem('platform_user',(res.success?JSON.stringify(res.data):''))
      })
    }
  }
}
</script>

<style scoped>

</style>
